package toanstt.com.gameplay;

import toanstt.com.MatchUp.App;
import toanstt.com.MatchUp.Button;
import toanstt.com.MatchUp.Notice;
import toanstt.com.MatchUp.Sound2;
import toanstt.com.MatchUp.T;
import toanstt.com.MatchUp.TBitmap2;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;

public class GameStatus 
{
	public static TBitmap2 BUTTON_BIT;
	TBitmap2 BUTTON_MENU_RE;
	public static Button BUTTON;
	Button BUTTON_MENU;
	Button BUTTON_REPLAY;
	public static int NUMHINT =3;
	public static int INHINT =0;
	public static int FAIL =0;
	public static String LEV="EASY";
	int d1;
	int D_TEXT;
	public GameStatus()
	{
		
	}
	public void NewGame(int i1,int i2)
	{
		FAIL =0;
		T.STATUS_MINX = T.GAME_MINX + T.GAME_WIDTH;
		T.STATUS_MINY = 20;
		T.STATUS_WIDTH   = (T.DISPLAY_WIDTH -T.STATUS_MINX);
		T.STATUS_MAXY = T.DISPLAY_HEIGHT -50;
		//BUTTON_BIT = new TBitmap2("gamestatus_button.png",1,4,(int)(T.DISPLAY_HEIGHT -50 - (T.GAME_MINY + T.GAME_HEIGHT) ),true);
		BUTTON_BIT = new TBitmap2("gamestatus_button.png",1,4,(int)((T.DISPLAY_HEIGHT -50 - (T.GAME_MINY + T.GAME_HEIGHT) )*0.8f),true);
		NUMHINT =3;
		BUTTON = new Button(BUTTON_BIT.bitmap[NUMHINT], (T.DISPLAY_WIDTH/2 - BUTTON_BIT.bitmap[NUMHINT].getWidth()/2 ),(T.GAME_MINY + T.GAME_HEIGHT) );
		
		//BUTTON_MENU_RE = new TBitmap2("menu_replay.png",2,1,(int)((T.DISPLAY_WIDTH/2)*0.8));
		BUTTON_MENU_RE = new TBitmap2("menu_replay.png",2,1,(int)((T.GAME_MINY*0.8)),true);
		BUTTON_REPLAY = new Button(BUTTON_MENU_RE.bitmap[0], T.DISPLAY_WIDTH/2 - BUTTON_MENU_RE.bitmap[0].getWidth(),0);
		BUTTON_MENU = new Button(BUTTON_MENU_RE.bitmap[1], T.DISPLAY_WIDTH/2 ,0);
		
		for(int i =0;i<T.GAME_ROW;i++)
		{
			for(int j =0;j<T.GAME_COL;j++)
			{
				if(CellTable.CARD_SLIP_INDEX[i][j]!=-1)
					CellTable.CARD_SLIP_INDEX[i][j] = 1;
				
			}
		}
		INHINT =45;
		T.STATUS_MINY =BUTTON_MENU_RE.bitmap[0].getHeight(); 
		D_TEXT = (int)(T.U2*0.3);
	}
	public void Draw(Canvas canvas)
	{
		
		//canvas.drawBitmap(BUTTON.bitmap[NUMHINT], T.STATUS_MINX, T.STATUS_MINY, null);
		BUTTON.Draw2(canvas);
		BUTTON_REPLAY.Draw2(canvas);
		BUTTON_MENU.Draw2(canvas);
		if(INHINT>0)
			INHINT--;
		
		T.bitmapfont1.drawString(canvas, LEV + " | " + "FAIL: "+FAIL, T.DISPLAY_WIDTH/2 , T.STATUS_MINY - D_TEXT, 2);
		//T.bitmapfont.drawString(canvas, "FAIL: "+FAIL, T.STATUS_MINX + T.STATUS_WIDTH/2, 80 , 2);

	}
	public void touch(MotionEvent mo)
	{
		if(BUTTON.Kick(mo))
		{
			if(NUMHINT>0 && INHINT ==0)
			{
				for(int i =0;i<T.GAME_ROW;i++)
				{
					for(int j =0;j<T.GAME_COL;j++)
					{
						if(CellTable.CARD_SLIP_INDEX[i][j]!=-1)
							CellTable.CARD_SLIP_INDEX[i][j] = 1;
						
					}
				}
				NUMHINT--;
				INHINT =35;
				BUTTON.bitmap = BUTTON_BIT.bitmap[NUMHINT];
				T.sounds.Play(Sound2.SLIPALL);
			}
		}
		else if(BUTTON_REPLAY.Kick(mo))
		{
			T.notice.DoNotice(Notice.REPLAY, 0);
		}
		else if(BUTTON_MENU.Kick(mo))
		{
			T.notice.DoNotice(Notice.MENU, 0);
		}
		
		
		if(App.action == MotionEvent.ACTION_UP)
		{
			BUTTON.anpla =255;
			BUTTON_REPLAY.anpla =255;
			BUTTON_MENU.anpla =255;
		}
	}
}
